package de.sabram.upb.specs.eee_tools.wizards;

import org.eclipse.core.resources.IFile;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
import org.eclipse.ui.ide.IDE;

public abstract class EEENewFile extends Wizard implements INewWizard{

	private IWorkbench _workbench;
	protected IStructuredSelection _selection;
	protected WizardNewFileCreationPage _pageOne;

	public EEENewFile(String wizardName) {
		setWindowTitle(wizardName);
	}

	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {
		_workbench = workbench;
		_selection = selection;
	}

	@Override
	public boolean performFinish() {
		boolean result = false;
		IFile file = _pageOne.createNewFile();
		result = file != null;
		if(result){
			try{
				IDE.openEditor(_workbench.getActiveWorkbenchWindow().getActivePage(), file);
			}
			catch(PartInitException e){
				e.printStackTrace();
			}
		}
		return result;
	}

}